home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / phillip2 / pattern.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-03  |  9.4 KB  |  389 lines

  1.  
  2.     /***********************************************
  3.     *
  4.     *    file d:\cips\pattern.c
  5.     *
  6.     *    Functions: This file contains
  7.     *       main
  8.     *
  9.     *    Purpose:
  10.     *       I use this program to create simple
  11.     *       patterns in images for illustrations.
  12.     *
  13.     *    External Calls:
  14.     *       gpcips.c - my_clear_text_screen
  15.     *       wtiff.c - create_allocate_tiff_file
  16.     *                 write_array_into_tiff_image
  17.     *
  18.     *    Modifications:
  19.     *       31 March 1991 - created
  20.     *       17 May 1993 - made this a command
  21.     *           line driven program.
  22.     *
  23.     ***********************************************/
  24.  
  25. #include "cips.h"
  26. #undef STUFF
  27.  
  28.  
  29. short p1[10][10] = 
  30.    {{11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  31.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  32.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  33.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  34.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  35.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  36.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  37.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  38.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  39.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11}};
  40.  
  41. short p2[10][10] = 
  42.    {{11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  43.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  44.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  45.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  46.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  47.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  48.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  49.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  50.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
  51.     {11, 11, 11, 11, 11, 11, 11, 11, 11, 11}};
  52.  
  53.  
  54.  
  55.  
  56. short out_image[ROWS][COLS];
  57.  
  58. main(argc, argv)
  59.    int argc;
  60.    char *argv[];
  61. {
  62.    int      count, i, ie, ii, il, j, jj, le, l, ll,
  63.             new_ie, new_il, set_i, set_j, square_size, w;
  64.    struct   tiff_header_struct image_header;
  65.  
  66.  
  67.    my_clear_text_screen();
  68.  
  69.    if(argc < 4 ){
  70.       printf("\n usage: pattern file-name "
  71.              "length width\n"
  72.              "\n the program will multiply length "
  73.              "and width"
  74.              "\n by %d and %d", ROWS, COLS);
  75.       exit(-1);
  76.    }
  77.  
  78.    l = atoi(argv[2]);
  79.    w = atoi(argv[3]);
  80.  
  81.    image_header.lsb            = 1;
  82.    image_header.bits_per_pixel = 8;
  83.    image_header.image_length   = l*ROWS;
  84.    image_header.image_width    = w*COLS;;
  85.    image_header.strip_offset   = 1000;
  86.  
  87.    create_allocate_tiff_file(argv[1], &image_header, 
  88.                              out_image);
  89.  
  90.    new_ie = 1;
  91.    new_il = 1;
  92.    il     = 1;
  93.    ie     = 1;
  94.    ll     = ROWS+1;
  95.    le     = COLS+1;
  96.  
  97.    /********************************************/
  98.  
  99.  
  100.       /* make a blank image that is not zero */
  101.    for(i=0; i<ROWS; i++){
  102.       for(j=0; j<COLS; j++){
  103.            out_image[i][j] = 150;
  104.        }
  105.    }
  106.  
  107.    /********************************************/
  108.  
  109.    count = 1;
  110.    for(i=0; i<l; i++){
  111.       for(j=0; j<w; j++){
  112.          printf("\nRunning %d of %d", count, l*w);
  113.          count++;
  114.          write_array_into_tiff_image(argv[1], out_image,
  115.                          new_il + i*ROWS,
  116.                          new_ie + j*COLS,
  117.                          new_il + i*ROWS + ROWS,
  118.                          new_ie + j*COLS + COLS);
  119.       }
  120.    }
  121.  
  122. }  /* ends main */
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. #ifdef STUFF
  130.  
  131.  
  132. /*
  133.    The following are samples patterns you can stick
  134.    into the output image.
  135. */
  136.  
  137.  
  138.  
  139.  
  140.      /* make a step pattern of gray shades */
  141.    for(i=0; i<ROWS; i++)
  142.       for(j=0; j<COLS; j++)
  143.         out_image[i][j] = 0;
  144.    for(i=0; i<ROWS; i++)
  145.       for(j=10; j<20; j++)
  146.         out_image[i][j] = 5;
  147.    for(i=0; i<ROWS; i++)
  148.       for(j=20; j<30; j++)
  149.         out_image[i][j] = 10;
  150.    for(i=0; i<ROWS; i++)
  151.       for(j=30; j<40; j++)
  152.         out_image[i][j] = 20;
  153.  
  154.  
  155.      /*  make a club to look at thinning and mat */
  156.    for(i=0; i<ROWS; i++){
  157.       for(j=0; j<COLS; j++){
  158.         if( i>4 && i<11 && j>4 && j<17)
  159.           out_image[i][j] = 200;
  160.         else
  161.           out_image[i][j] = 0;
  162.     }
  163.    }
  164.    for(i=0; i<ROWS; i++){
  165.       for(j=0; j<COLS; j++){
  166.         if( i>1 && i<17 && j>4 && j<11)
  167.           out_image[i][j] = 200;
  168.     }
  169.    }
  170.  
  171.  
  172.       /*  make a rectangle with a hole in it */
  173.    for(i=0; i<ROWS; i++){
  174.       for(j=0; j<COLS; j++){
  175.         if( i>=5 && i<=8 && j>=5 && j<=18)
  176.           out_image[i][j] = 200;
  177.     }
  178.    }
  179.    for(i=0; i<ROWS; i++){
  180.       for(j=0; j<COLS; j++){
  181.         if( i>=15 && i<=18 && j>=5 && j<=18)
  182.           out_image[i][j] = 200;
  183.     }
  184.    }
  185.    for(i=0; i<ROWS; i++){
  186.       for(j=0; j<COLS; j++){
  187.         if( j>=5 && j<=8 && i>=5 && i<=18)
  188.           out_image[i][j] = 200;
  189.     }
  190.    }
  191.    for(i=0; i<ROWS; i++){
  192.       for(j=0; j<COLS; j++){
  193.         if( j>=15 && j<=18 && i>=5 && i<=18)
  194.           out_image[i][j] = 200;
  195.     }
  196.    }
  197.  
  198.      /* make the entire area white with a black hole
  199.      in it good for interior outline */
  200.    for(i=0; i<ROWS; i++){
  201.       for(j=0; j<COLS; j++){
  202.          if( i>=10 && i<=15 && j>=10 && j<=18)
  203.             out_image[i][j] = 0;
  204.          else
  205.             out_image[i][j] = 200;
  206.       }
  207.    }
  208.  
  209.  
  210.       /* make a square  */
  211.    for(i=0; i<ROWS; i++){
  212.       for(j=0; j<COLS; j++){
  213.          if( i>=8 && i<=18 && j>=8 && j<=18)
  214.             out_image[i][j] = 200;
  215.          else
  216.             out_image[i][j] = 0;
  217.       }
  218.    }
  219.  
  220.       /* make a square  with a hole in
  221.         it for closing practice */
  222.    for(i=0; i<ROWS; i++){
  223.       for(j=0; j<COLS; j++){
  224.          if( i>=8 && i<=13 && j>=8 && j<=13)
  225.             out_image[i][j] = 200;
  226.          else
  227.             out_image[i][j] = 0;
  228.       }
  229.    }
  230.    out_image[10][10] = 0;
  231.    out_image[11][10] = 0;
  232.  
  233.       /* make 2 small squares
  234.         illustrate closing and special closing */
  235.    for(i=0; i<ROWS; i++)
  236.       for(j=0; j<COLS; j++)
  237.          out_image[i][j] = 0;
  238.    for(i=0; i<ROWS; i++){
  239.       for(j=0; j<COLS; j++){
  240.          if( i>=8 && i<=13 && j>=8 && j<=9)
  241.             out_image[i][j] = 200;
  242.          if( i>=8 && i<=13 && j>=11 && j<=13)
  243.             out_image[i][j] = 200;
  244.       }
  245.    }
  246.  
  247.       /* make a rectangle  */
  248.    for(i=0; i<ROWS; i++){
  249.       for(j=0; j<COLS; j++){
  250.          if( i>=8 && i<=18 && j>=4 && j<=18)
  251.             out_image[i][j] = 200;
  252.          else
  253.             out_image[i][j] = 0;
  254.       }
  255.    }
  256.  
  257.       /* make a block letter A */
  258.    for(i=0; i<ROWS; i++)
  259.       for(j=0; j<COLS; j++)
  260.          out_image[i][j] = 0;
  261.    for(i=0; i<ROWS; i++)
  262.       for(j=0; j<COLS; j++)
  263.          if(i>=10 && i<=20 && j>=10 && j<=50)
  264.           out_image[i][j] = 200;
  265.    for(i=0; i<ROWS; i++)
  266.       for(j=0; j<COLS; j++)
  267.          if(i>=40 && i<=50 && j>=10 && j<=50)
  268.           out_image[i][j] = 200;
  269.    for(i=0; i<ROWS; i++)
  270.       for(j=0; j<COLS; j++)
  271.          if(i>=10 && i<=90 && j>=10 && j<=20)
  272.           out_image[i][j] = 200;
  273.    for(i=0; i<ROWS; i++)
  274.       for(j=0; j<COLS; j++)
  275.          if(i>=10 && i<=90 && j>=40 && j<=50)
  276.           out_image[i][j] = 200;
  277.  
  278.       /* make a broken line */
  279.    for(i=0; i<ROWS; i++)
  280.       for(j=0; j<COLS; j++)
  281.          out_image[i][j] = 0;
  282.    for(i=0; i<ROWS; i++)
  283.       for(j=0; j<COLS; j++)
  284.          if(i>=10 && i<=11 && j>=5 && j<=18)
  285.           out_image[i][j] = 200;
  286.    out_image[10][11] = 0;
  287.    out_image[11][11] = 0;
  288.  
  289.  
  290.       /* make two squares joined together */
  291.    for(i=0; i<ROWS; i++)
  292.       for(j=0; j<COLS; j++)
  293.          out_image[i][j] = 0;
  294.    for(i=0; i<ROWS; i++){
  295.       for(j=0; j<COLS; j++){
  296.          if( i>=5 && i<=15 && j>=5 && j<=9)
  297.             out_image[i][j] = 200;
  298.          if( i>=5 && i<=15 && j>=12 && j<=17)
  299.             out_image[i][j] = 200;
  300.       }
  301.    }
  302.    out_image[10][10] = 200;
  303.    out_image[10][11] = 200;
  304.  
  305.  
  306.  
  307.  
  308.    /* make a texture, checkerboard of 100-200
  309.       with each square the size given by the 
  310.       variable square_size 
  311.       I'll do this a little different and let
  312.       the user specify the square size as the
  313.       last parameter on the line. */
  314.  
  315.    sqaure_size = atoi(argv[4]);
  316.    ii=0; 
  317.    jj=0; 
  318.    set_i=0; 
  319.    set_j=0;
  320.    for(i=0; i<ROWS; i++){
  321.       for(j=0; j<COLS; j++){
  322.  
  323.             /* odd rows */
  324.          if( (set_i%2) == 0){
  325.             if( (set_j%2) == 0)
  326.                out_image[i][j] = 100;
  327.             else
  328.                out_image[i][j] = 200;
  329.          }
  330.             /* even rows */
  331.          else{
  332.             if( (set_j%2) == 0)
  333.                out_image[i][j] = 200;
  334.             else
  335.                out_image[i][j] = 100;
  336.          }
  337.  
  338.          jj++;
  339.          if(jj > square_size){
  340.             jj = 0;
  341.             set_j++;
  342.          }
  343.       }  /* ends loop over j */
  344.  
  345.       jj=0; 
  346.       set_j=0;
  347.       ii++;
  348.       if(ii > square_size){
  349.          ii = 0;
  350.          set_i++;
  351.       }
  352.    }  /* ends loop over i */
  353.  
  354.  
  355.       /* create a random image 0-255 */
  356.    for(i=0; i<ROWS; i++)
  357.       for(j=0; j<COLS; j++)
  358.         out_image[i][j] = (rand() % 255);
  359.  
  360.  
  361.       /* create a random image 100-150  */
  362.    for(i=0; i<ROWS; i++)
  363.       for(j=0; j<COLS; j++)
  364.         out_image[i][j] = 100 + (rand() %  50);
  365.  
  366.  
  367.       /* make vertical stripes */
  368.    for(i=0; i<ROWS; i++){
  369.       for(j=0; j<COLS; j++){
  370.            if( (j > 10  &&  j < 30)    ||
  371.                (j > 50  &&  j < 70)    ||
  372.                (j > 90  &&  j < 99) )
  373.                out_image[i][j] = 200;
  374.             else
  375.                out_image[i][j] = 50;
  376.        }
  377.    }
  378.  
  379.  
  380.       /* make a blank image that is not zero */
  381.    for(i=0; i<ROWS; i++){
  382.       for(j=0; j<COLS; j++){
  383.            out_image[i][j] = 150;
  384.        }
  385.    }
  386.  
  387.  
  388. #endif
  389.